home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsdps.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.0 KB  |  115 lines

  1. /* Copyright (C) 1997, 1998 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsdps.c,v 1.2 2000/09/19 19:00:28 lpd Exp $ */
  20. /* Display PostScript extensions */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gsdps.h"
  24. #include "gspath.h"        /* for newpath */
  25. #include "gxdevice.h"        /* for gxcpath.h */
  26. #include "gzpath.h"        /* for gzcpath.h */
  27. #include "gzstate.h"
  28. #include "gzcpath.h"
  29.  
  30. /* ---------------- View clipping ---------------- */
  31.  
  32. /* Forward references */
  33. private int common_viewclip(P2(gs_state *, int));
  34.  
  35. int
  36. gs_initviewclip(gs_state * pgs)
  37. {
  38.     gx_clip_path *pcpath = pgs->view_clip;
  39.  
  40.     if (pcpath != 0 && pcpath->rule != 0) {
  41.     gx_cpath_reset(pcpath);
  42.     pcpath->rule = 0;
  43.     }
  44.     return 0;
  45. }
  46.  
  47. int
  48. gs_viewclip(gs_state * pgs)
  49. {
  50.     return common_viewclip(pgs, gx_rule_winding_number);
  51. }
  52.  
  53. int
  54. gs_eoviewclip(gs_state * pgs)
  55. {
  56.     return common_viewclip(pgs, gx_rule_even_odd);
  57. }
  58.  
  59. /* This code is (almost) copied from common_clip in gspath.c. */
  60. /* Someday we'll find a way to merge them. */
  61. private int
  62. common_viewclip(gs_state * pgs, int rule)
  63. {
  64.     gs_fixed_rect bbox;
  65.     gx_clip_path rpath;
  66.     int code;
  67.     gx_clip_path *pcpath = pgs->view_clip;
  68.  
  69.     if (pcpath == 0) {
  70.     pcpath = gx_cpath_alloc(pgs->memory, "gs_[eo]viewclip");
  71.     if (pcpath == 0)
  72.         return_error(gs_error_VMerror);
  73.     pgs->view_clip = pcpath;
  74.     }
  75.     if ((code = gx_path_bbox(pgs->path, &bbox)) < 0)
  76.     return code;
  77.     gx_cpath_init_local(&rpath, pgs->memory);
  78.     code = gx_cpath_from_rectangle(&rpath, &bbox);
  79.     if (code >= 0)
  80.     code = gx_cpath_clip(pgs, &rpath, pgs->path, rule);
  81.     if (code < 0) {
  82.     gx_cpath_free(&rpath, "gs_[eo]viewclip");
  83.     return code;
  84.     }
  85.     rpath.rule = rule;
  86.     gx_cpath_assign_free(pcpath, &rpath);
  87.     gs_newpath(pgs);
  88.     return 0;
  89. }
  90.  
  91. int
  92. gs_viewclippath(gs_state * pgs)
  93. {
  94.     gx_path cpath;
  95.     gx_clip_path *pcpath = pgs->view_clip;
  96.     int code;
  97.  
  98.     gx_path_init_local(&cpath, pgs->memory);
  99.     if (pcpath == 0 || pcpath->rule == 0) {
  100.     /* No view clip path is active: fabricate one. */
  101.     gs_fixed_rect box;
  102.  
  103.     code = gx_default_clip_box(pgs, &box);
  104.     if (code < 0)
  105.         return code;
  106.     code = gx_path_add_rectangle(&cpath, box.p.x, box.p.y,
  107.                      box.q.x, box.q.y);
  108.     } else {
  109.     code = gx_cpath_to_path(pcpath, &cpath);
  110.     }
  111.     if (code < 0)
  112.     return code;
  113.     return gx_path_assign_free(pgs->path, &cpath);
  114. }
  115.